; (function ($) {
  var Mesgbox = function (ele, opt) {
    this.$element = ele,
    this.defaults = {
      msg: "msg",
      bgcolor: "#AAD7FF",
      fade: true,
      second: 3,
      togglespeed: 0.2
    },
    this.setting = $.extend({}, this.defaults, opt),
    this.creatMsgbox = function () {
      var boxClass = "infos_box";
      var boxDesc = "infos_desc";
      var defaultBoxCss = {
        "position": "fixed",
        "display": "none",
        "bottom": "5%",
        "width": "80%",
        "z-index": "50",
        "left": "50%",
        "margin-left": "-40%",
        "padding": "0px",
        "box-sizing": "border-box",
        "background": "#AAD7FF",
        "border-radius": "10px",
        "-webkit-border-radius": "10px"
      };
      var defaultDescCss = {
        "width": "100%",
        "position": "relative",
        "text-align": "center",
        "vertical-align": "middle",
        "font-size": "0.4rem",
        "font-weight": "600",
        "color": "#000000",
        "display": "block",
        "padding-top": "1vh",
        "padding-bottom": "1vh"

      };
      var msgs = " ";
      var box = {};
      msgs = "<div class='" + boxClass + "'><p class='" + boxDesc + "'></p></div>";
      box.boxClass = boxClass;
      box.boxDesc = boxDesc;
      box.msgs = msgs;
      box.defaultBoxCss = defaultBoxCss;
      box.defaultDescCss = defaultDescCss;
      return box;
    }
  }
  Mesgbox.prototype = {
    init: function () {
      var t;
      var msgbox;
      var $this = this;
      msgbox = this.creatMsgbox();
      if (!this.$element.has("." + msgbox.boxClass).length) {
        this.$element.append(msgbox.msgs);
      }
      $("." + msgbox.boxDesc).css(msgbox.defaultDescCss).text(this.setting.msg);
      $("." + msgbox.boxClass).css(msgbox.defaultBoxCss).css({
        "background": $this.setting.bgcolor
      }).fadeIn("" + $this.setting.togglespeed * 1000 + "", function () {
        if ($this.setting.fade) {
          clearTimeout(t);
          t = setTimeout(function () {
            $(".infos_box").fadeOut("" + $this.setting.togglespeed * 1000 + "");
          }, $this.setting.second * 1000);
        }
      });
      var obj = $("." + msgbox.boxClass);
      return obj;
    },
    destroy: function (opt) {
      if ($(opt).length) {
        $(opt).remove();
      } else {
        $.error("Dom " + opt + " is not exist");
      }
    }
  }
  $.fn.msgbox = function (options) {
    var box = new Mesgbox(this, options);
    if (box[options]) {
      return box[options].apply(this, Array.prototype.slice.call(this, arguments));
    } else if (typeof options === 'object' || !options) {
      return box.init();
    } else {
      $.error("Method " + options + " is not exist on jQuery.msgbox");
    }
  }
})(jQuery)